package ai.people.platform.archives.controller;

import ai.people.core.plugin.annotation.HotRefresh;
import ai.people.netmon.framework.domain.archives.request.ArchivesRequest;
import ai.people.netmon.framework.domain.archives.request.NetworkActivitiesRequest;
import ai.people.netmon.framework.domain.archives.vo.*;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.platform.archives.service.ArchivesService;
import com.vesoft.nebula.client.graph.exception.IOErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * 档案接口
 *
 * @author zhenglin
 * @since 2022/3/23
 */
@HotRefresh
@RefreshScope
@RestController
@RequestMapping("/v1")
public class ArchivesController {

    /**
     * 档案服务
     */
    @Autowired
    private ArchivesService archivesService;


    /**
     * 添加档案
     *
     * @param archives 档案
     * @return {@link Result}<{@link String}>
     * @throws InterruptedException         中断异常
     * @throws IOErrorException             ioerror异常那么
     * @throws UnsupportedEncodingException 不支持编码异常
     */
    @Deprecated
    @PostMapping()
    public Result<String> addArchives(@Validated @RequestBody ArchivesAddVO archives) throws InterruptedException, IOErrorException, UnsupportedEncodingException, ExecutionException {
        String archivesId = archivesService.addArchives(archives);
        return ResultUtil.success(archivesId);
    }

    /**
     * 更新档案
     *
     * @param archives 档案
     * @return {@link Result}<{@link Boolean}>
     */
    @Deprecated
    @PutMapping
    public Result<Boolean> updateArchives(@Validated @RequestBody ArchivesVO archives) throws InterruptedException, IOErrorException, UnsupportedEncodingException, ExecutionException {
        archivesService.updateArchives(archives);
        return ResultUtil.success();
    }

    /**
     * 档案列表
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link ArchivesListVO}>>
     */
    @PostMapping("/list")
    public Result<PageResponse<ArchivesListVO>> listArchives(@RequestBody ArchivesRequest request) {
        PageResponse<ArchivesListVO> response = archivesService.listArchives(request);
        return ResultUtil.success(response);
    }

    /**
     * 我的档案列表
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link ArchivesListVO}>>
     */
    @PostMapping("/myArchives")
    public Result<PageResponse<ArchivesListVO>> myListArchives(@RequestBody ArchivesRequest request) {
        PageResponse<ArchivesListVO> response = archivesService.myListArchives(request);
        return ResultUtil.success(response);
    }

    /**
     * 档案详情
     *
     * @param id id
     * @return {@link Result}<{@link ArchivesDetailVO}>
     */
    @GetMapping("/{id}")
    public Result<ArchivesDetailVO> getArchives(@PathVariable("id") Long id) {
        ArchivesDetailVO archivesDetailVO = archivesService.getArchives(id);
        return ResultUtil.success(archivesDetailVO);
    }

    /**
     * 获取隐藏档案详情
     *
     * @param id id
     * @return {@link Result}<{@link ArchivesDetailVO}>
     */
    @GetMapping("/hide/{id}")
    public Result<ArchivesDetailVO> getHideArchives(@PathVariable("id") Long id) {
        ArchivesDetailVO archivesDetailVO = archivesService.getHideArchives(id);
        return ResultUtil.success(archivesDetailVO);
    }

    /**
     * 档案详情2
     *
     * @param id id
     * @return {@link Result}<{@link ArchivesDetail2VO}>
     */
    @GetMapping("/detail/{id}")
    public Result<ArchivesDetail2VO> getArchivesDetail(@PathVariable("id") Long id) {
        ArchivesDetail2VO archivesDetailVO = archivesService.getArchivesDetail(id);
        return ResultUtil.success(archivesDetailVO);
    }

    /**
     * 网络活动列表
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link NetworkActivitiesVO}>>
     */
    @PostMapping("/search")
    public Result<PageResponse<NetworkActivitiesVO>> listNetworkActivities(@Validated @RequestBody NetworkActivitiesRequest request) {
        PageResponse<NetworkActivitiesVO> result = archivesService.listNetworkActivities(request);
        return ResultUtil.success(result);
    }


    /**
     * 档案列表(团伙库)
     *
     * @return {@link Result}<{@link List}<{@link GangGroupArchivesVO}>>
     */
    @GetMapping("/gang/list")
    public Result<List<GangGroupArchivesVO>> listForGangGroup() {
        List<GangGroupArchivesVO> result = archivesService.listForGangGroup();
        return ResultUtil.success(result);
    }

    /**
     * 档案详情(团伙库)
     *
     * @param id id
     * @return {@link Result}<{@link GangGroupArchivesVO}>
     */
    @GetMapping("/gang/{id}")
    public Result<GangGroupArchivesVO> getForGangGroup(@PathVariable("id") Long id) {
        GangGroupArchivesVO result = archivesService.getForGangGroup(id);
        return ResultUtil.success(result);
    }

}
